package logic.nodes.lod.blocks;

import gameStates.absGamesStates.AbsIngameState;
import logic.nodes.collision.CollidableNode;

import com.jme.bounding.BoundingBox;
import com.jme.math.Vector3f;

public abstract class AbstractBlock {
		
	protected BoundingBox box;
	protected Block parentBlock;
	protected AbsIngameState ingameState;
	
	public AbstractBlock(Vector3f center, float size, AbsIngameState ingameState) {
		this(center, size, size, size, ingameState);
	}
	
	public AbstractBlock(Vector3f center, float xExtend, float yExtend, float zExtend, AbsIngameState ingameState) {
		this.ingameState = ingameState;
		
		box = new BoundingBox(center, xExtend, yExtend, zExtend);
	}
	
	public boolean intersectsWith(CollidableNode node) {
		assert(node.getBound() != null);
		return box.intersects(node.getBound());
	}
	
	public boolean intersectsWith(AbstractBlock block) {
		return box.intersects(block.getBox());
	}
	
	public void setParentBlock(Block parentBlock) {
		this.parentBlock = parentBlock;
	}
	
	public Block getParentBlock() { return parentBlock; }
		
	public BoundingBox getBox() { return box; }
	
	public Vector3f getCenter() { return box.getCenter(); }
		
	public void accept(BlockVisitor visitor) { visitor.visit(this); }

	public AbsIngameState getIngameState() { return ingameState; }
}